﻿using System;
using System.Data;
using System.Configuration;
using System.Collections;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Web.UI.HtmlControls;
using Mmht.BT;

public partial class jxzy_jdwx : BasePage
{
    GetPdf getPdf = new GetPdf();
    public int pagesize = 10;
    public int pages = 0;
    public int page = 0;
    public string page_url;
    public string sort_url;
    public string sortFiled = "name";
    public string sortCls1 = "";
    public string sortCls2 = "";
    public string sortCls3 = "";

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            if (Session["type"] == null)
            {
                Response.Redirect("login.aspx");
                return;
            }
            if (Request["page"] != null)
            {
                string p = Request["page"];
                page = int.Parse(p);
            }
            else
            {
                page = 1;
            }
            if (Request["sort"] != null)
            {
                sortFiled = Request["sort"];
            }
            else
            {
                sortFiled = "name";
            }
            page = page <= 0 ? 1 : page;
            page_url = Request.Url.ToString().Split('?')[0];
            sort_url = page_url + "?sort=";
            page_url += "?sort=" + sortFiled + "&page=[i]";
            controlRepeater();
        }

    }

    private void controlRepeater()
    {
        DataTable table1 = getPdf.Get_Recommended_Pdf("文献");
        DataTable table2_1 = getPdf.Get_All_Pdf("文献");
        DataTable table3 = getPdf.Get_CTRtop_Pdf("文献", 8);
        switch (sortFiled)
        {
            case "viewnum":
                table2_1.DefaultView.Sort = "viewnum DESC";
                sortCls2 = "cur";
                break;
            case "time":
                table2_1.DefaultView.Sort = "created_at DESC";
                sortCls3 = "cur";
                break;
            default:
                table2_1.DefaultView.Sort = "name_cn ASC";
                sortCls1 = "cur";
                break;
        }
        DataTable table2 = table2_1.DefaultView.ToTable(); 

        PagedDataSource pds = new PagedDataSource();
        pds.DataSource = table2.DefaultView;
        pds.PageSize = pagesize;
        pds.AllowPaging = true;
        pds.CurrentPageIndex = page - 1;

        int dataTotal = table2.Rows.Count;
        pages = dataTotal % pagesize == 0 ? dataTotal / pagesize : dataTotal / pagesize + 1;
        pages = pages == 0 ? 1 : pages;
        this.Repeater2.DataSource = pds;
        this.Repeater2.DataBind();

        this.Repeater1.DataSource = table3;
        this.Repeater1.DataBind();

        this.Repeater3.DataSource = table1;
        this.Repeater3.DataBind();
    }

    private void changSortFiled()
    {

    }


    public string getViewHostClass(Object number)
    {
        return ViewHotBT.getViewHostClass(number);
    }
}